package com.hmall.service;

import com.hdmall.business.common.util.OSSClientUtil;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;

@Service
public class UpDownServiceImpl {

    private OSSClientUtil ossClient=new OSSClientUtil();
    public String updateHead(MultipartFile file) throws Exception {
        if (file == null || file.getSize() <= 0) {
            throw new Exception("文件不能为空");
        }
        String name = ossClient.uploadImg2Oss(file);
        //userDao.updateHead(userId, imgUrl);//只是本地上传使用的
        return ossClient.getImgUrl(name);
    }
    String updatePDFHead(String fileName, InputStream is)  {
        /*if (file == null || file.getSize() <= 0) {
            throw new Exception("文件不能为空");
        }*/
        String name = null;
        try {
            name = ossClient.uploadPdf2Oss(fileName,is);
        } catch (Exception e) {
            e.printStackTrace();
        }
        //userDao.updateHead(userId, imgUrl);//只是本地上传使用的
        return ossClient.getImgUrl(name);
    }

}